<template>
	<view class="beijingse mainpadding">
		<view class="mainpadding ffffff radius">
			<view class="flexbetween">
				<view class="ershib">账号</view>
				<input class="inputs textright" type="text" placeholder="请输入转赠手机号" v-model="mobile">
			</view>
			<view class="flexbetween margin_top">
				<input class="inputs" type="number" placeholder="请输入验证码" v-model="captcha">
				<view class="huangsetext textright" @click="sendcode">{{codetext}}</view>
			</view>
		</view>
		<view class="mainpadding ffffff radius margin_top">
			<view class="flexbetween">
				<view class="ershib">转赠数</view>
				<input class="inputs textright" type="number" placeholder="请输入转赠数" v-model="bonus_price">
			</view>
		</view>
		<view class="gudingdb" @click="submit">
			<view class="bigbtn">确认转赠</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				valueType:0,//0奖金，1积分
				mobile:"",
				captcha:"",
				bonus_price:'',
				codetext:"获取验证码"
			}
		},
		onLoad(options) {
			this.valueType = options.type
		},
		methods: {
			submit(){
				let data = {
					mobile:this.mobile,
					captcha:this.captcha,
					integral_price:this.bonus_price
				}
				let _this = this
				let mobile = _this.mobile;
				if (this.mobile == '') {
					httpRequest.toast('请输入手机号');
					return false;
				}
				if (!mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				if (this.captcha == '') {
					httpRequest.toast('请输入验证码');
					return false;
				}
				if (this.bonus_price == '') {
					httpRequest.toast('请输入转赠数');
					return false;
				}
				let url = ""
				if(this.valueType==0){
					data.bonus_price = data.integral_price
					delete data.integral_price
					url = "/api/user/zzBonusprice"
				}else{
					url = "/api/user/zzIntegralprice"
				}
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// 发送验证码
			sendcode() {
				let _this = this
				let mobile = _this.mobile;
				if (!mobile.match(/^1\d{10}$/)) {
					httpRequest.toast("请输入有效的手机号码");
					return false;
				}
				httpRequest.request('/api/sms/send', 'GET', {
					mobile: mobile,
					event: "zzcer"
				}).then(resp => {
					if (resp.code == 1) {
						var i = 60;
						var timer = setInterval(function() {
							_this.codetext = i + "秒";
							if (i < 1) {
								clearInterval(timer);
								_this.codetext = "获取验证码";
							} else {
								i--;
							}
						}, 1000)
			
					} else if (resp.code == 0) {
						httpRequest.toast(resp.msg);
					} else {
						httpRequest.toast('网络开小差啦');
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.huangsetext{
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
		width: 200rpx;
	}
	.inputs{
		width: 50%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}
	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}
</style>
